package com.ywh.composetest.activity

import android.os.Bundle
import android.util.Log
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.lifecycle.LifecycleEventObserver

class DisposableEffectActivity : BaseComposeActivity() {
    @Composable
    override fun OnComposable(savedInstanceState: Bundle?) {
        DisposableEffect(this) {
            val observer = LifecycleEventObserver { _, event ->
                Log.e("SecondActivity", "event:${event.name}")
            }
            lifecycle.addObserver(observer)
            onDispose {
                Log.e("SecondActivity", "onDispose")
                lifecycle.removeObserver(observer)
            }
        }
    }
}